<script type="text/javascript" src="ckeditor/ckeditor.js"></script>
<script type="text/javascript">
function listSubCategory(cat,sub_cat) 
{
	var category = document.getElementById(cat).value;

	$.post("ajax_file.php", {module:'Classifieds', process:'listClassiCat', category: category}, function (getResult){
		$('#'+sub_cat+' option').remove();
		$('#'+sub_cat).append('<option value=""></option>');
		$('#'+sub_cat).append(getResult);
	});
}

</script>

<?php
$id = $_REQUEST['_d'];
$page = $_REQUEST['page'];

if($_REQUEST['_a'] != "u" && $_REQUEST['_a'] != "d")
{
$q = mysql_fetch_array(mysql_query("select * from classifieds_ads where Id='$id'"));
?>
<?php
if($_REQUEST['_s'] == 1)
{ ?>
	<table align="center" border="0">
	<tr>
    	<td align="center"><div class="sucmsg"><img src="images/information.png" align="absmiddle" />&nbsp;Updated Successfully</div></td>
    </tr>    
    </table>
<?php } ?>

<script type="text/javascript" src="includes/fancybox/jquery-1.4.2.min.js"></script>
<script type="text/javascript" src="includes/fancybox/jquery.mousewheel-3.0.2.pack.js"></script>
<script type="text/javascript" src="includes/fancybox/jquery.fancybox-1.3.1.js"></script>
<link rel="stylesheet" type="text/css" href="includes/fancybox/jquery.fancybox-1.3.1.css" media="screen" />
<link rel="stylesheet" href="includes/fancybox_style.css" />

<script type="text/javascript">
		$(document).ready(function() {
			/*
			*   Examples - images
			*/

			$("a#1").fancybox({
				'titleShow'		: false,
				'transitionIn'	: 'elastic',
				'transitionOut'	: 'elastic'
			});
			$("a#2").fancybox({
				'titleShow'		: false,
				'transitionIn'	: 'elastic',
				'transitionOut'	: 'elastic'
			});
			$("a#3").fancybox({
				'titleShow'		: false,
				'transitionIn'	: 'elastic',
				'transitionOut'	: 'elastic'
			});
			$("a#4").fancybox({
				'titleShow'		: false,
				'transitionIn'	: 'elastic',
				'transitionOut'	: 'elastic'
			});
			$("a#5").fancybox({
				'titleShow'		: false,
				'transitionIn'	: 'elastic',
				'transitionOut'	: 'elastic'
			});
			$("a#6").fancybox({
				'titleShow'		: false,
				'transitionIn'	: 'elastic',
				'transitionOut'	: 'elastic'
			});

			$("a[rel=example_group]").fancybox({
				'transitionIn'		: 'none',
				'transitionOut'		: 'none',
				'titlePosition' 	: 'over',
				'titleFormat'		: function(title, currentArray, currentIndex, currentOpts) {
					return '<span id="fancybox-title-over">Image ' + (currentIndex + 1) + ' / ' + currentArray.length + (title.length ? ' &nbsp; ' + title : '') + '</span>';
				}
			});

			/*
			*   Examples - various
			*/

			$("#various1").fancybox({
				'titlePosition'		: 'inside',
				'transitionIn'		: 'none',
				'transitionOut'		: 'none'
			});

			$("#various2").fancybox();

			$("#various3").fancybox({
				'width'				: '75%',
				'height'			: '75%',
				'autoScale'			: false,
				'transitionIn'		: 'none',
				'transitionOut'		: 'none',
				'type'				: 'iframe'
			});

			$("#various4").fancybox({
				'padding'			: 0,
				'autoScale'			: false,
				'transitionIn'		: 'none',
				'transitionOut'		: 'none'
			});
		});
	</script>

<form name="up" action="index.php?tc=classifieds_ads_view&_d=<?php echo $id;?>&page=<?php echo $page;?>&_a=u" method="post">
<table width="99%" align="center" border="0"  class="list">
<thead>
<tr>
	<td colspan="2" align="left">
        <div style="float:left" class="righthead">ADS</div>
        <div style="float:right"><a href="index.php?tc=classifieds_ads&page=<?php echo $page;?>" class="back">Back</a></div>
    </td>
</tr>
</thead>
<tr>
	<td width="150"><strong>Item Name</strong></td>
    <td><input type="text" name="itemname" value="<?php echo $q['Item'];?>" /></td>
</tr>
<tr>
	<td width="150"><strong>Description</strong></td>
    <td><textarea name="desc" id="elm1" cols="80" rows="5" wrap="soft"><?php echo $q["Description"];?></textarea></td>
</tr>
<tr>
	<td width="150"><strong>Category</strong></td>
    <td>
       <select name="category" id="category" onchange="listSubCategory('category','sub_category');">
    		<?php 
			$sql = "SELECT * FROM classifieds_category WHERE active_status='1'";
			$res = mysql_query($sql) or die(mysql_error());
			$i=1;
			while($data = mysql_fetch_array($res)) {
				if($q['Category'] == $data['id']) {
					echo '<option value="'.$data['id'].'" selected>'.stripslashes($data['category']).'</option>';
				}
				else {
					echo '<option value="'.$data['id'].'"  >'.stripslashes($data['category']).'</option>';
				}
			}
			?>
       </select>
    </td>
</tr> 
<tr>
	<td align="right" width="150">Sub Category</td>
    <td align="left">
    	<select name="sub_category" id="sub_category">
    		<?php 
			$sql = "SELECT * FROM classifieds_subcategory WHERE active_status='1'";
			$res = mysql_query($sql) or die(mysql_error());
			$i=1;
			while($data = mysql_fetch_array($res)) {
				if($q['sub_category'] == $data['id']) {
					echo '<option value="'.$data['id'].'" selected>'.stripslashes($data['sub_cat_name']).'</option>';
				}
				else {
					echo '<option value="'.$data['id'].'"  >'.stripslashes($data['sub_cat_name']).'</option>';
				}
			}
			?>
       </select>     
      </td> 
</tr>
<tr>
	<td width="150"><strong>Listing Level</strong></td>
    <td><?php if($q["ListingLevel"]==1) echo "Standard"; else echo "Premium";?></td>
</tr>  
<tr>
	<td width="150"><strong>Template Images</strong></td>
    <td>
    	<?php
		if($q["TempImage1"] != "") { ?> <a rel="example_group" id="1" href="../uploads/adimages/<?php echo $q['TempImage1'];?>"><img src="images/view_image_big.png" border="0"></a><?php }
		if($q["TempImage2"] != "") { ?>  <a rel="example_group" id="2" href="../uploads/adimages/<?php echo $q['TempImage2'];?>"><img src="images/view_image_big.png"  border="0"></a><?php }
		if($q["TempImage3"] != "") { ?>  <a rel="example_group" id="3" href="../uploads/adimages/<?php echo $q['TempImage3'];?>"><img src="images/view_image_big.png"  border="0"></a><?php }
		if($q["TempImage4"] != "") { ?>  <a rel="example_group" id="4" href="../uploads/adimages/<?php echo $q['TempImage4'];?>"><img src="images/view_image_big.png"  border="0"></a><?php }
		if($q["TempImage5"] != "") { ?>  <a rel="example_group" id="5" href="../uploads/adimages/<?php echo $q['TempImage5'];?>"><img src="images/view_image_big.png"  border="0"></a><?php }
		if($q["TempImage6"] != "") { ?>  <a rel="example_group" id="6" href="../uploads/adimages/<?php echo $q['TempImage6'];?>"><img src="images/view_image_big.png"  border="0"></a><?php }
		?>
    </td>
</tr>   
<tr>
	<td width="150"><strong>Contact Email</strong></td>
    <td><input type="text" name="email" value="<?php echo $q['ContactEmail'];?>" /></td>
</tr>  
<tr>
	<td width="150"><strong>Show Email</strong></td>
    <td>
    	<input type="radio" value="1" name="showcontactemail" <?php if($q["ShowEmail"]==1) echo "checked";?>  />&nbsp;Yes&nbsp;&nbsp;
        	<input type="radio" value="0" name="showcontactemail" <?php if($q["ShowEmail"]==0) echo "checked";?> />No
    </td>
</tr> 
<tr>
	<td width="150"><strong>Address1</strong></td>
    <td><input type="text" name="address1" value="<?php echo $q['Address1'];?>" /></td>
</tr> 
<tr>
	<td width="150"><strong>Address2</strong></td>
    <td><input type="text" name="address2" value="<?php echo $q['Address2'];?>" /></td>
</tr> 
<tr>
	<td width="150"><strong>City</strong></td>
    <td><input type="text" name="city" value="<?php echo $q['City'];?>" /></td>
</tr> 
<tr>
	<td width="150"><strong>State</strong></td>
    <td><input type="text" name="state" value="<?php echo $q['State'];?>" /></td>
</tr>
<tr>
	<td width="150"><strong>Postcode</strong></td>
    <td><input type="text" name="postcode" value="<?php echo $q['Postcode'];?>" /></td>
</tr> 
<tr>
	<td width="150"><strong>Phone</strong></td>
    <td><input type="text" name="phone" value="<?php echo $q['Phone'];?>" /></td>
</tr> 
<tr>
	<td width="150"><strong>Fax</strong></td>
    <td><input type="text" name="fax" value="<?php echo $q['Fax'];?>" /></td>
</tr>
<tr>
	<td width="150"><strong>Business Description</strong></td>
    <td>
    <textarea name="maincont" id="maincont" class="textarea" cols="25" rows="5"><?php echo stripslashes($q["BusinessDesc"]);?></textarea>
     <script type="text/javascript">CKEDITOR.replace( 'maincont',{skin : 'kama'});</script>
   
</tr> 
<tr>
	<td width="150"><strong>Total Amount</strong></td>
    <td>$<?php echo $q["TotalAmount"];?></td>
</tr> 
<tr>
	<td width="150"><strong>TransactionId</strong></td>
    <td><?php echo $q["TransactionId"];?></td>
</tr>
<tr>
	<td width="150"><strong>Inserted Date</strong></td>
    <td><?php echo $q["InsertedDate"];?></td>
</tr>
<tr>
	<td width="150"><strong>Status</strong></td>
    <td>
    	<select name="status">
        	<option value="0" <?php if($q["Status"]==0) echo "selected";?>>Pending</option>
            <option value="1" <?php if($q["Status"]==1) echo "selected";?>>Approved</option>
       	</select>     
    </td> 
</tr> 
<tr>
	<td colspan="2" style="padding-left:155px;">
    	<input type="submit" value="Update" >&nbsp;&nbsp;
        
    </td>
</tr>        
</table>   
</form> 
<?php
}

if($_REQUEST['_a']=="u")
{
	$status = $_POST['status'];
	$itemname = $_POST['itemname'];
	$desc = $_POST['desc'];
	$cat = $_POST['category'];
	$sub_cat = $_POST['sub_category'];
	$email = $_POST['email'];
	$showcontactemail = $_POST['showcontactemail'];
	$address1 = $_POST['address1'];
	$address2 = $_POST['address2'];
	$city = $_POST['city'];
	$state = $_POST['state'];
	$postcode = $_POST['postcode'];
	$phone = $_POST['phone'];
	$fax = $_POST['fax'];
	$businessdesc = mysql_real_escape_string($_POST['maincont']);

	mysql_query("update classifieds_ads set Status='$status', ApprovedDate=now(), Item='$itemname', Description='".mysql_real_escape_string($desc)."', Category='$cat',sub_category='$sub_cat', ContactEmail='$email', ShowEmail='$showcontactemail', Address1='$address2', Address1='".mysql_real_escape_string($address2)."', City='".mysql_real_escape_string($city)."', State='".mysql_real_escape_string($state)."', Postcode='$postcode', Phone='$phone', Fax='$fax', BusinessDesc='".mysql_real_escape_string($businessdesc)."' where Id='$id'");
	//header("location:index.php?tc=classifieds_ads_view&_d=$id&page=$page&_s=1");
	echo "<script>window.location='index.php?tc=classifieds_ads_view&_d=$id&page=$page&_s=1'</script>";
}
if($_REQUEST['_a']=="d")
{
	$q = mysql_fetch_array(mysql_query("select * from classifieds_ads where Id='$id'"));
	$path1 = "../uploads/adimages/".$q['TempImage1'];
	$thumb_path1 = "../uploads/adimages/".$q['TempImage1'];
	unlink($path1);
	unlink($thumb_path1);
	$path2 = "../uploads/adimages/".$q['TempImage2'];
	$thumb_path2 = "../uploads/adimages/".$q['TempImage2'];
	unlink($path2);
	unlink($thumb_path2);
	$path3 = "../uploads/adimages/".$q['TempImage3'];
	$thumb_path3 = "../uploads/adimages/".$q['TempImage3'];
	unlink($path3);
	unlink($thumb_path3);
	$path4 = "../uploads/adimages/".$q['TempImage4'];
	$thumb_path4 = "../uploads/adimages/".$q['TempImage4'];
	unlink($path4);
	unlink($thumb_path4);
	$path5 = "../uploads/adimages/".$q['TempImage5'];
	$thumb_path5 = "../uploads/adimages/".$q['TempImage5'];
	unlink($path5);
	unlink($thumb_path5);
	$path6 = "../uploads/adimages/".$q['TempImage6'];
	$thumb_path6 = "../uploads/adimages/".$q['TempImage6'];
	unlink($path6);
	unlink($thumb_path6);
	mysql_query("delete from classifieds_ads where Id='$id'");
	//header("location:index.php?tc=classifieds_ads&page=$page&_s=2");
	echo "<script>window.location='index.php?tc=classifieds_ads&page=$page&_s=2'</script>";
}
?>